package com.mxchip.livestar.base

import android.app.Activity
import android.view.View
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import com.mxchip.livestar.base.hideSystemUI

class HideSystemUILifecycleAware : LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun auditStarted(){

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    fun auditCreated(owner: LifecycleOwner){

        if(owner is Activity) {
            owner.window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
                // Note that system bars will only be "visible" if none of the
                // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
                    // adjustments to your UI, such as showing the action bar or
                    // other navigational controls.
                    owner.window.hideSystemUI()
                } else {
                    // adjustments to your UI, such as hiding the action bar or
                    // other navigational controls.
                }
            }
        }

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun auditPaused(){

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    fun auditStopped(){

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun auditDestroyed(){

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun auditResumed(owner: LifecycleOwner){

        if(owner is Activity) {
            owner.window.hideSystemUI()
        }
    }
}